package com.dippersoft.rick.databindtest;

import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.dippersoft.rick.databindtest.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    TestData testData = new TestData("Desc str", 77);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
//        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//        binding.setTestData01(new TestData("Desc02", 777));
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        testData.name.set("Rick Pan");
        binding.setTestData01(testData);
        binding.setHandlers(new CallBacks());

        Log.i("TTT", "Started.");
    }

    public class CallBacks {
        public void onClick(View view) {
            switch (view.getId())
            {
                case R.id.textView2:
                    new Thread(new TestThread()).start();
                    Log.i("TTT", testData.getStrData01());
                    break;

                case R.id.button:
                    testData.setStrData01("New description.");
                    testData.setIntData01(7);
                    testData.name.set("Rick");
                    break;
            }
        }
    }

    public class TestThread implements Runnable {
        @Override
        public void run() {
            Log.i("TTT", "In thread");
            testData.setStrData01("Changed in thread.");
            testData.setIntData01(777);
            testData.name.set("Change name in thread.");
        }
    }
}
